<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib.js"></script>
</head>
<body>
    
    <div id="content">
        <h4>阶乘练习</h4>
        阶乘：<input id="factorial" type="text" /><br />
        结果：<input id="result" type="text" /><br />
        <button onclick="cal()">计算</button><br />
        阶乘和：<input id="factorialSum" type="text" />示例：1 2 3<br />
        结果：<input id="resultSum" type="text"/><br />
        <button onclick="calSum()">计算</button><br />
    </div>
</body>
<script>
    var data = document.getElementById('factorial');
    var result = document.getElementById('result');

    function cal() {
        var facResult = factorial(Number(data.value));
        result.value = facResult;
    }

    var sumData = document.getElementById("factorialSum");
    var resultSum = document.getElementById("resultSum");

    function calSum() {
        var sum = 0;
        var array = sumData.value.split(' ');
        for (let i = 0; i < array.length; i++) {
            var ele = Number(array[i]);
            sum += factorial(ele);
        }
        resultSum.value = sum;
    }


    
</script>
</html>